package org.visionlibrary.image.filters.adjustement;

import javax.media.jai.TiledImage;

import org.visionlibrary.image.model.AbstractFilter;


public class BackgroundClear extends AbstractFilter {
	public static final int DEFAULT_BACKGROUND = 255;
	
	private int background = 255;
	
	public int getBackground() {
		return background;
	}

	public void setBackground(int background) {
		this.background = background;
	}

	@Override
	public TiledImage applyFilter(TiledImage src, TiledImage dest) {
		if (null == src)
			throw new NullPointerException("Source image is null.");
			
		int maxX = src.getWidth();
		int maxY = src.getHeight();

		for (int x = 0; x < maxX; x++)
			for (int y = 0; y < maxY; y++) {
				for (int ch = 0; ch < src.getNumBands(); ch++) {
					src.setSample(x, y, ch, background);
				}
			}

		return src;
	}
}
